//https://www.nowcoder.com/practice/64b4262d4e6d4f6181cd45446a5821ec?tpId=13&tqId=625&ru=%2Fpractice%2F106f666170554379ab1974e5a601e741&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D13
// 思想：遍历到任何一个位置的时候，都要问自己当前卖的话，最大利润是多少？
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param prices int整型vector 
     * @return int整型
     */
    int maxProfit(vector<int>& prices) {
        // write code here
        if(prices.empty()||prices.size() == 1) return 0;
        int min_num = *prices.begin();
        int res = 0;
        for(int j = 1;j<prices.size();++j) {
            if(min_num <=prices[j]) {
                res = std::max(res,prices[j]-min_num);   
            }
            min_num = prices[j] < min_num? prices[j]:min_num;
        }
        return res;
    }
};